package com.ljx.controller;

import com.ljx.common.ResponseResult;
import com.ljx.domain.dto.RoleStatusDto;
import com.ljx.domain.entity.Role;
import com.ljx.service.MenuService;
import com.ljx.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 李捷禧
 * Date: 2023/4/22
 * ClassName: RoleController
 */

@RestController
@RequestMapping("/system/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping("/list")
    public ResponseResult list(Integer pageNum, Integer pageSize,String roleName,String status){
        return roleService.listAll(pageNum,pageSize,roleName,status);
    }

    @GetMapping("/listAllRole")
    public ResponseResult listAll(){
        List<Role> roles = roleService.list();
        return ResponseResult.okResult(roles);
    }

    @GetMapping("{id}")
    public ResponseResult getOne(@PathVariable Long id){
        Role role = roleService.getById(id);
        return ResponseResult.okResult(role);
    }

    @PutMapping
    public ResponseResult update(@RequestBody Role role){
        roleService.updateById(role);
        return ResponseResult.okResult("更新成功");
    }

    @PutMapping("/changeStatus")
    public ResponseResult changeStatus(@RequestBody RoleStatusDto roleStatusDto){
      return  roleService.changeStatus(roleStatusDto);
    }

    @PostMapping
    public ResponseResult add(@RequestBody Role role){
        roleService.save(role);
        return ResponseResult.okResult("新增成功");
    }

    @DeleteMapping("{id}")
    public ResponseResult delete(@PathVariable List<Long> id){
        roleService.removeByIds(id);
        return ResponseResult.okResult("删除成功");
    }

}
